package com.winit.cloudAgent.service;

import com.alibaba.fastjson.JSONObject;
import com.winit.mq.exchange.MessageExchange;
import com.winit.mq.message.Message;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by wanglin on 2018/1/17.
 */
@Service
public class WerbsocketSendService {
    private static Logger logger = LoggerFactory.getLogger(WerbsocketSendService.class);

    @Autowired
    private MessageExchange messageExchange;

    public void send(JSONObject jsonObject){
        try {
            logger.info("开始发送web通知，开始时间："+new Date().getTime());
            Message message = new Message();
            message.setBody(jsonObject);
//            if(StringUtils.isNoneEmpty(webNotifyJson.getString("group"))){
//                messageExchange.sendMessage("WebNotify_" + webNotifyJson.getString("group"), message);
//            }
                messageExchange.sendMessage("clouldTest", message);

        }catch (Exception e){
            logger.error("发送异常："+e.getMessage());
        }
        finally {
            logger.info("结束消息，结束时间："+new Date().getTime());
        }
    }
}
